package net.morlhon.nabaztag

import java.net.URL
import java.net.URLEncoder

class NabaztagExecutor(sn:String,token:String) {
  val baseString : String = "http://api.nabaztag.com/vl/FR/api.jsp?"

  def execute(messages: List[Message] ) {
    var apiString : String = ""
    
    for(m <- messages) {
       m match {
       case Say(message,voice) => {
         apiString += "tts=" + URLEncoder.encode(message)
         if (voice != null && voice.length > 0) {
           apiString+="&voice=" + voice
         }
       }
       case Move(ears) => apiString += ears.code 
       }
    }
    val finalString = baseString + "sn=" + sn + "&token=" + token + "&" + apiString
    new URL(finalString).getContent()
  }
  
}